package com.magenta.maxoptra.gis.commons;

import java.io.Serializable;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * User: Дима
 * Date: 16.12.12
 * Time: 23:12
 * To change this template use File | Settings | File Templates.
 */
public class Quadruple<First, Second, Third, Fourth> implements Serializable {
    private static final long serialVersionUID = 5682924741755269710L;

    private final First first;
    private final Second second;
    private final Third third;
    private final Fourth fourth;

    /**
     * Default constructor.
     * @param first element.
     * @param second element.
     * @param third element.
     */
	public Quadruple(First first, Second second, Third third, Fourth fourth) {
		this.first = first;
		this.second = second;
		this.third = third;
        this.fourth = fourth;
	}

	public First getFirst() {
		return first;
	}

	public Second getSecond() {
		return second;
	}

	public Third getThird() {
		return third;
	}

    public Fourth getFourth() {
        return fourth;
    }

	@Override
	public int hashCode() {
		return Arrays.hashCode(toArray());
	}

	@Override
	public boolean equals(Object obj) {
		return (obj instanceof Quadruple) && Arrays.equals(toArray(), ((Quadruple) obj).toArray());
	}

	@Override
	public String toString() {
		StringBuilder info = new StringBuilder();
		info.append('{').append(first).append(',').append(second).append(',').append(third).append('}').append(fourth).append('}');
		return info.toString();
	}

	/**
	 * @return triple as array.
	 */
	public Object[] toArray() {
		return new Object[] {first, second, third, fourth};
	}

    public static<F, S, T, Fth> Quadruple<F, S, T, Fth> generate(Triple<F, S, T> triple, Fth t) {
   		return new Quadruple<F, S, T, Fth>(triple.getFirst(), triple.getSecond(), triple.getThird(), t);
   	}

	public static<F, S, T, Fth> Quadruple<F, S, T, Fth> generate(F f, S s, T t, Fth fth) {
		return new Quadruple<F, S, T, Fth>(f, s, t, fth);
	}
}